package com.caesar.Date.second_generation;

import org.junit.jupiter.api.Test;

import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;

/**
 * @author caesar
 * @date 2025/7/15
 * @Description:java.util.Calendar
 *      `Calendar` 类是一个抽象类`
 *      它为特定瞬间与一组日历字段之间的转换提供了一些方法
 *      并为操作日历字段（例如获得下星期的日期）提供了一些方法
 *      `Calendar` 提供了一个类方法 `getInstance`，以获得此类型的一个通用的对象。
 * @apiNote
 */
public class TestCalendar {
    @Test
    public void test1(){
        Calendar c = Calendar.getInstance();//获取默认的系统是日期时间，以当前运行环境的时区和语言环境来获取日历对象
        System.out.println(c);
        /*
        java.util.GregorianCalendar[time=1752542624606,areFieldsSet=true,areAllFieldsSet=true,lenient=true,
        zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,transitions=31,lastRule=null],
        firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,
        YEAR=2025,MONTH=6,WEEK_OF_YEAR=29,WEEK_OF_MONTH=3,DAY_OF_MONTH=15,DAY_OF_YEAR=196,
        DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=23,SECOND=44,
        MILLISECOND=606,ZONE_OFFSET=28800000,DST_OFFSET=0]
         */

        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;
        int day = c.get(Calendar.DAY_OF_MONTH);

        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        System.out.println(year +"年" + month + "月" + day + "日 " + hour + ":" + minute);
    }

    @Test
    public void test2(){
        TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
        Locale locale = Locale.US;
        Calendar c = Calendar.getInstance(zone,locale);
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;
        int day = c.get(Calendar.DAY_OF_MONTH);

        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        System.out.println(year +"年" + month + "月" + day + "日 " + hour + ":" + minute);
        //2025年7月14日 18:28
    }
}
